import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:tender_flutter/constant/theme_colors.dart';
import 'package:tender_flutter/page/home/model/credit_entity.dart';
import 'package:tender_flutter/utils/screen_adaper.dart';

class CreditListCell extends StatelessWidget {
  const CreditListCell({Key key, this.data}) : super(key: key);

  final CreditList data;

  @override
  Widget build(BuildContext context) {
    return _initCell();
  }

  Widget _initCell() {
    Map<String, dynamic> maps = {
      "被执行人": data.dishonestName,
      "案号": data.caseCode,
      "立案时间": data.regDate,
      "身份证/机构代码": data.cardNum,
      "负责人": data.businessEntity,
      "执行法院": data.courtName,
      "省份": data.areaName,
      "执行依据文号": data.gistId,
      "执行单位": data.gistUnit,
    };
    Map<String, dynamic> bigMaps = {
      "法律职责": data.legalDuty,
      "履行情况": data.performance,
      "被执行人行为具体情况": data.disruptTypeName
    };

    return Container(
        // width: double.infinity,
        margin: EdgeInsets.symmetric(
            vertical: ScreenAdapter.height(20),
            horizontal: ScreenAdapter.width(20)),
        child: Column(children: [
          Table(
            //所有列宽
            columnWidths: const {
              //列宽
              0: FixedColumnWidth(150),
              1: FixedColumnWidth(200),
            },
            defaultVerticalAlignment: TableCellVerticalAlignment.middle,
            //表格边框样式
            border: TableBorder.all(
              width: 0.5,
              color: ThemeColors.colorType47,
              style: BorderStyle.solid,
            ),
            children: maps.keys.map((e) => _getTableCell(e, maps[e])).toList(),
          ),
          Table(
            //所有列宽
            columnWidths: const {
              //列宽
              0: FixedColumnWidth(350),
            },
            defaultVerticalAlignment: TableCellVerticalAlignment.middle,
            border: TableBorder(
                left: BorderSide(
                  width: 0.5,
                  color: ThemeColors.colorType47,
                  style: BorderStyle.solid,
                ),
                right: BorderSide(
                  width: 0.5,
                  color: ThemeColors.colorType47,
                  style: BorderStyle.solid,
                ),
                bottom: BorderSide(
                  width: 0.5,
                  color: ThemeColors.colorType47,
                  style: BorderStyle.solid,
                )),
            children: bigMaps.keys
                .map((e) => _getBitTableCell(e, bigMaps[e]))
                .toList(),
          ),
        ]));
  }

  TableRow _getTableCell(String title, dynamic content) {
    return TableRow(children: [
      Container(
        // height: ScreenAdapter.height(70),
        padding: EdgeInsets.symmetric(
            vertical: ScreenAdapter.height(20),
            horizontal: ScreenAdapter.width(20)),
        alignment: Alignment.centerLeft,
        child: Text(
          title,
          style: TextStyle(
              color: ThemeColors.colorType24,
              fontSize: ScreenAdapter.sp(28),
              fontWeight: FontWeight.w500),
        ),
      ),
      Container(
        // height: ScreenAdapter.height(70),
        padding: EdgeInsets.symmetric(
            vertical: ScreenAdapter.height(15),
            horizontal: ScreenAdapter.width(20)),
        alignment: Alignment.centerLeft,
        child: Text(
          content.toString(),
          style: TextStyle(
              color: ThemeColors.colorType7,
              fontSize: ScreenAdapter.sp(28),
              fontWeight: FontWeight.w400),
        ),
      ),
    ]);
  }

  TableRow _getBitTableCell(String title, dynamic content) {
    return TableRow(children: [
      Container(
          padding: EdgeInsets.symmetric(
              vertical: ScreenAdapter.height(20),
              horizontal: ScreenAdapter.width(20)),
          child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              mainAxisAlignment: MainAxisAlignment.start,
              children: [
                Text(
                  title ?? "",
                  style: TextStyle(
                      color: ThemeColors.colorType24,
                      fontSize: ScreenAdapter.sp(28),
                      fontWeight: FontWeight.w500),
                ),
                SizedBox(height: ScreenAdapter.height(20)),
                Text(
                  content ?? "",
                  style: TextStyle(
                      color: ThemeColors.colorType7,
                      fontSize: ScreenAdapter.sp(28),
                      fontWeight: FontWeight.w400),
                )
              ]))
    ]);
  }
}
